<?php
ini_set( "display_errors", 0);
include 'configuration.php';

if(isset($_POST['id']) && isset($_POST['ip']) && isset($_POST['code']))
{		
	//if all params set, post
	$id = $_POST['id'];
	$ip = $_POST['ip'];
	$code = $_POST['code'];
	
	
	
	echo "<script>\n";
	echo "window.location = 'http://mandurah.inf.ed.ac.uk/index.php?code=".$code."';\n";	
	echo "</script>\n";
	echo "Your IP was updated successfully.";
	
	//retrieve the access token
	$link = mysql_connect('localhost', $DBUSER, $DBPASS) or die('Could not connect: ' . mysql_error());
	mysql_select_db('facebook') or die('Could not select database');
	
	$query = "update users set address='$ip' where id='$id'";
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	
	mysql_free_result($result);
	mysql_close($link);
}

?>
